package com.zmyuan.demo.netty.websocket.socket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;


/**
 * Created by zdb on 2017/2/14.
 */
public class WebsocketChannelInitializer extends ChannelInitializer<SocketChannel> {

    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new HttpRequestDecoder())
                .addLast(new HttpObjectAggregator(65536))
                .addLast(new HttpResponseEncoder())
//                .addLast(new WebsocketServerHandler()); // 单用户聊天
                .addLast(new WebSocketServerProtocolHandler("/websocket"))
                .addLast(new ChatRoomHandler());
    }
}
